package l1j.server.server.datatables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

import l1j.server.L1DatabaseFactory;
import l1j.server.server.utils.SQLUtil;
import l1j.server.server.utils.collections.Maps;

public class ClanSkillTable {
	private static ClanSkillTable _instance = new ClanSkillTable();

	public static ClanSkillTable getInstance() {
		return _instance;
	}

	public static void initilize() {
		_instance = new ClanSkillTable();
	}

	private Map<Integer, AllClanSkillDetail> _allDetail_ById = Maps.newMap();

	private ClanSkillTable() {
		Connection con = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		try {
			con = L1DatabaseFactory.getInstance().getConnection();
			pstm = con.prepareStatement("SELECT * FROM x_clan_skill");

			rs = pstm.executeQuery();
			while (rs.next()) {
				AllClanSkillDetail cs = new AllClanSkillDetail();
				cs.setClan_skill_id(rs.getInt("clan_skill_id"));
				cs.setClan_skill_name(rs.getString("clan_skill_name"));
				cs.setClan_skill_note(rs.getString("clan_skill_note"));
				cs.setClan_skill_value(rs.getString("clan_skill_value"));
				cs.setUpdate_price(rs.getString("update_price"));
				cs.setUpdate_item_1(rs.getString("update_item_1"));
				cs.setUpdate_item_1_count(rs.getString("update_item_1_count"));
				cs.setUpdate_item_2(rs.getString("update_item_2"));
				cs.setUpdate_item_2_count(rs.getString("update_item_2_count"));
				int clan_skill_id = rs.getInt("clan_skill_id");
				_allDetail_ById.put(clan_skill_id, cs);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			SQLUtil.close(rs);
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}
	
	public AllClanSkillDetail getClanSkillDetail(int clan_skill_id) {
		AllClanSkillDetail cs = _allDetail_ById.get(clan_skill_id);
		return cs;
	}

	public class AllClanSkillDetail {
		private int clan_skill_id = 0;
		private String clan_skill_name = "";
		private String clan_skill_note = "";
		private String clan_skill_value = "";
		private String update_price = "";
		private String update_item_1 = "";
		private String update_item_1_count = "";
		private String update_item_2 = "";
		private String update_item_2_count = "";

		public int getClan_skill_id() {
			return clan_skill_id;
		}

		public void setClan_skill_id(int clan_skill_id) {
			this.clan_skill_id = clan_skill_id;
		}

		public String getClan_skill_name() {
			return clan_skill_name;
		}

		public void setClan_skill_name(String clan_skill_name) {
			this.clan_skill_name = clan_skill_name;
		}

		public String getClan_skill_note() {
			return clan_skill_note;
		}

		public void setClan_skill_note(String clan_skill_note) {
			this.clan_skill_note = clan_skill_note;
		}
		
		public String[] getClan_skill_value() {
			String[] value = clan_skill_value.split(",");
			return value;
		}

		public void setClan_skill_value(String clan_skill_value) {
			this.clan_skill_value = clan_skill_value;
		}
		
		public String[] getUpdate_price() {
			String[] price = update_price.split(",");
			return price;
		}

		public void setUpdate_price(String update_price) {
			this.update_price = update_price;
		}

		public String[] getUpdate_item_1() {
			String[] item_1 = update_item_1.split(",");
			return item_1;
		}

		public void setUpdate_item_1(String update_item_1) {
			this.update_item_1 = update_item_1;
		}
		
		public String[] getUpdate_item_1_count() {
			String[] item_1_count = update_item_1_count.split(",");
			return item_1_count;
		}

		public void setUpdate_item_1_count(String update_item_1_count) {
			this.update_item_1_count = update_item_1_count;
		}
		
		public boolean checkUpdate_item_2() {
			if (update_item_2.equalsIgnoreCase("0")) {
				return false;
			}
			return true;
		}
		
		public String[] getUpdate_item_2() {
			String[] item_2 = update_item_2.split(",");
			return item_2;
		}

		public void setUpdate_item_2(String update_item_2) {
			this.update_item_2 = update_item_2;
		}
		
		public String[] getUpdate_item_2_count() {
			String[] item_2_count = update_item_2_count.split(",");
			return item_2_count;
		}

		public void setUpdate_item_2_count(String update_item_2_count) {
			this.update_item_2_count = update_item_2_count;
		}
	}
}